
package interrupt;


public class Register {
    private short reg;
    public Register(){
        reg = 0;
    }
    
    @Override
    public String toString(){
        StringBuffer result = new StringBuffer(Integer.toHexString(reg));
        while(result.length() < 4){
            result.insert(0, "0");
        }
        while(result.length() > 4){
            result.delete(0, 1);
        }
        return result.toString();
    }
    
    public void setReg(short data){
        this.reg = data;
    }
    
    public void setReg(String DATA){
        this.reg = Short.parseShort(DATA, 16);
    }
    
    public short getReg(){
        return this.reg;
    }
    
    public void setBit(byte num, boolean value){
        short temp = (short) (this.reg >>> (16-num));
        if(temp%2 == 0 && value){
            temp++;
        }
        if(temp%2 == 1 && !value)
            temp--;
        //System.out.println(temp);
        temp = (short) (temp << (16-num));
        temp += this.reg << num >>> num;
        this.reg = temp;
    }
}
